﻿using System;
using System.Collections.Generic;

namespace IOA.MES.DataAccess.VModel
{
    /// <summary>
    /// 工单表
    /// </summary>
    public class VWorkOrder : BaseVModel
    {
        private string _orderNo = string.Empty;
        private string _workOrderNo = string.Empty;
        private string _remark = string.Empty;
        private string _customerCode = string.Empty;
        private string _customerName = string.Empty;
        private string _productCode = string.Empty;
        private string _productName = string.Empty;
        private string _versionDesc = string.Empty;
        private string _workOrderCategoryName = string.Empty;
        private string _workOrderCategoryCode = string.Empty;
        private string _workshopName = string.Empty;
        private string _workshopCode = string.Empty;
        private string _erpWorkOrderNo = string.Empty;
        private string _erpRecord = string.Empty;
        private string _cellLevel = string.Empty;
        private string _cellModel = string.Empty;
        private string _innerOrderNo = string.Empty;
        private string _productSpecs = string.Empty;
        private string _contractNo = string.Empty;
        private string _assistUnitCode = string.Empty;
        private string _lineId = string.Empty;
        private string _lineName = string.Empty;
        private string _protocolNo = string.Empty;
        private string _projectName = string.Empty;
        private string _standardLevel = string.Empty;
        private string _glassType = string.Empty;

        #region Public Property

        ///<Summary>
        /// 订单号
        ///</Summary>
        public string OrderNo
        {
            get { return string.IsNullOrWhiteSpace(_orderNo) ? string.Empty : _orderNo; }
            set { _orderNo = value; }
        }

        ///<Summary>
        /// 订单行号
        ///</Summary>
        public int OrderRowNum { get; set; }

        ///<Summary>
        /// 内部单号
        ///</Summary>
        public string InnerOrderNo
        {
            get { return string.IsNullOrWhiteSpace(_innerOrderNo) ? string.Empty : _innerOrderNo; }
            set { _innerOrderNo = value; }
        }

        ///<Summary>
        /// 工单号
        ///</Summary>
        public string WorkOrderNo
        {
            get { return string.IsNullOrWhiteSpace(_workOrderNo) ? string.Empty : _workOrderNo; }
            set { _workOrderNo = value; }
        }

        ///<Summary>
        /// 执行标准
        ///</Summary>
        public string StandardLevel
        {
            get { return string.IsNullOrWhiteSpace(_standardLevel) ? string.Empty : _standardLevel; }
            set { _standardLevel = value; }
        }

        /// <summary>
        /// 销售合同号
        /// </summary>
        public string ContractNo
        {
            get { return string.IsNullOrWhiteSpace(_contractNo) ? string.Empty : _contractNo; }
            set { _contractNo = value; }
        }

        /// <summary>
        /// 协议号
        /// </summary>
        public string ProtocolNo
        {
            get { return string.IsNullOrWhiteSpace(_protocolNo) ? string.Empty : _protocolNo; }
            set { _protocolNo = value; }
        }

        /// <summary>
        /// 项目名称
        /// </summary>
        public string ProjectName
        {
            get { return string.IsNullOrWhiteSpace(_projectName) ? string.Empty : _projectName; }
            set { _projectName = value; }
        }

        ///<Summary>
        /// 生产订单主表标识
        ///</Summary>
        public int ErpWorkOrderId { get; set; }

        ///<Summary>
        /// ERP生产订单号
        ///</Summary>
        public string ErpWorkOrderNo
        {
            get { return string.IsNullOrWhiteSpace(_erpWorkOrderNo) ? string.Empty : _erpWorkOrderNo; }
            set { _erpWorkOrderNo = value; }
        }

        ///<Summary>
        /// ERP生产订单行号
        ///</Summary>
        public int ErpWorkOrderRowNum { get; set; }

        ///<Summary>
        /// 辅助计量单位编码
        ///</Summary>
        public string AssistUnitCode
        {
            get { return string.IsNullOrWhiteSpace(_assistUnitCode) ? string.Empty : _assistUnitCode; }
            set { _assistUnitCode = value; }
        }

        ///<Summary>
        /// 订单子表ID
        ///</Summary>
        public int ErpOrderChildId { get; set; }

        ///<Summary>
        /// 生产订单子表标识
        ///</Summary>
        public int ErpWorkOrderChildId { get; set; }

        ///<Summary>
        /// 换算率
        ///</Summary>
        public decimal? ConversionRate { get; set; }

        /// <summary>
        /// ERP状态
        /// </summary>
        public int ERPWorkOrderStatus { get; set; }

        ///<Summary>
        /// 客户ID
        ///</Summary>
        public int CustomerId { get; set; }

        ///<Summary>
        /// 客户代码
        ///</Summary>
        public string CustomerCode
        {
            get { return string.IsNullOrWhiteSpace(_customerCode) ? string.Empty : _customerCode; }
            set { _customerCode = value; }
        }

        ///<Summary>
        /// 客户名称
        ///</Summary>
        public string CustomerName
        {
            get { return string.IsNullOrWhiteSpace(_customerName) ? string.Empty : _customerName; }
            set { _customerName = value; }
        }

        ///<Summary>
        /// 下单时间
        ///</Summary>
        public DateTime WorkOrderTime { get; set; }

        ///<Summary>
        /// 车间代码
        ///</Summary>
        public string WorkshopCode
        {
            get { return string.IsNullOrWhiteSpace(_workshopCode) ? string.Empty : _workshopCode; }
            set { _workshopCode = value; }
        }

        ///<Summary>
        /// 车间名称
        ///</Summary>
        public string WorkshopName
        {
            get { return string.IsNullOrWhiteSpace(_workshopName) ? string.Empty : _workshopName; }
            set { _workshopName = value; }
        }

        ///<Summary>
        /// 班次ID
        ///</Summary>
        public int DutyId { get; set; }

        /// <summary>
        /// 产线ID
        /// </summary>
        public string LineId
        {
            get { return string.IsNullOrWhiteSpace(_lineId) ? string.Empty : _lineId; }
            set { _lineId = value; }
        }

        /// <summary>
        /// 产线名称
        /// </summary>
        public string LineName
        {
            get { return string.IsNullOrWhiteSpace(_lineName) ? string.Empty : _lineName; }
            set { _lineName = value; }
        }

        ///<Summary>
        /// 成品编码
        ///</Summary>
        public string ProductCode
        {
            get { return string.IsNullOrWhiteSpace(_productCode) ? string.Empty : _productCode; }
            set { _productCode = value; }
        }

        ///<Summary>
        /// 成品物料名称
        ///</Summary>
        public string ProductName
        {
            get { return string.IsNullOrWhiteSpace(_productName) ? string.Empty : _productName; }
            set { _productName = value; }
        }

        ///<Summary>
        /// 成品物料规格
        ///</Summary>
        public string ProductSpecs
        {
            get { return string.IsNullOrWhiteSpace(_productSpecs) ? string.Empty : _productSpecs; }
            set { _productSpecs = value; }
        }

        ///<Summary>
        /// 生产数量
        ///</Summary>
        public int Count { get; set; }

        ///<Summary>
        /// 工单备注
        ///</Summary>
        public string Remark
        {
            get { return string.IsNullOrWhiteSpace(_remark) ? string.Empty : _remark; }
            set { _remark = value; }
        }

        ///<Summary>
        /// 工单状态
        ///</Summary>
        public Enum.ProduceStatus Status { get; set; }

        /// <summary>
        /// 工单状态
        /// </summary>
        public string CNStatus { get { return !System.Enum.IsDefined(typeof(Enum.ProduceStatus), Status) ? string.Empty : EnumConvert.ToDesc(Status); } }

        /// <summary>
        /// 工单类型
        /// </summary>
        public string WorkOrderCategoryCode
        {
            get { return string.IsNullOrWhiteSpace(_workOrderCategoryCode) ? string.Empty : _workOrderCategoryCode; }
            set { _workOrderCategoryCode = value; }
        }

        /// <summary>
        /// 工单类型名称
        /// </summary>
        public string WorkOrderCategoryName
        {
            get { return string.IsNullOrWhiteSpace(_workOrderCategoryName) ? string.Empty : _workOrderCategoryName; }
            set { _workOrderCategoryName = value; }
        }

        /// <summary>
        /// 开工日期
        /// </summary>
        public DateTime? StartDate { get; set; }

        /// <summary>
        /// 完工日期
        /// </summary>
        public DateTime? EndDate { get; set; }

        /// <summary>
        /// 版本号
        /// </summary>
        public int? Version { get; set; }

        /// <summary>
        /// 版本说明
        /// </summary>
        public string VersionDesc
        {
            get { return string.IsNullOrWhiteSpace(_versionDesc) ? string.Empty : _versionDesc; }
            set { _versionDesc = value; }
        }

        /// <summary>
        /// ERP数据记录
        /// </summary>
        public string ErpRecord
        {
            get { return string.IsNullOrWhiteSpace(_erpRecord) ? string.Empty : _erpRecord; }
            set { _erpRecord = value; }
        }

        /// <summary>
        /// ERP审核时间
        /// </summary>
        public DateTime? ReviewTime { get; set; }

        /// <summary>
        /// ERP修改时间
        /// </summary>
        public DateTime? UpdateTime { get; set; }

        /// <summary>
        /// 电池片数量
        /// </summary>
        public int? CellQuantity { get; set; }

        /// <summary>
        /// 电池等级
        /// </summary>
        public string CellLevel
        {
            get { return string.IsNullOrWhiteSpace(_cellLevel) ? string.Empty : _cellLevel; }
            set { _cellLevel = value; }
        }

        /// <summary>
        /// 玻璃类型
        /// </summary>
        public string GlassType
        {
            get { return string.IsNullOrWhiteSpace(_glassType) ? string.Empty : _glassType; }
            set { _glassType = value; }
        }

        /// <summary>
        /// 电池型号
        /// </summary>
        public string CellModel
        {
            get { return string.IsNullOrWhiteSpace(_cellModel) ? string.Empty : _cellModel; }
            set { _cellModel = value; }
        }

        /// <summary>
        /// 单片功率
        /// </summary>
        public decimal? SingleCellPower { get; set; }

        /// <summary>
        /// 电池效率
        /// </summary>
        public decimal? CellEfficiencyMin { get; set; }

        /// <summary>
        /// 电池效率
        /// </summary>
        public decimal? CellEfficiencyMax { get; set; }

        /// <summary>
        /// Q等级列表
        /// </summary>
        public List<VWorkOrderQLevel> QLevels { get; set; } = new List<VWorkOrderQLevel>();

        /// <summary>
        /// 产出功率
        /// </summary>
        public List<VWorkOrderOutputPower> OutputPowers { get; set; } = new List<VWorkOrderOutputPower>();

        /// <summary>
        /// 功率档列表
        /// </summary>
        public List<VBinningPower> BinningPowers { get; set; } = new List<VBinningPower>();
        #endregion


        public string StartDateStr { get { return StartDate?.ToString("yyyy-MM-dd") ?? string.Empty; } }
        public string EndDateStr { get { return EndDate?.ToString("yyyy-MM-dd") ?? string.Empty; } }
        public string WorkOrderTimeStr { get { return WorkOrderTime.ToString("yyyy-MM-dd HH:mm:ss"); } }
        public string ReviewTimeStr { get { return ReviewTime?.ToString("yyyy-MM-dd HH:mm:ss") ?? string.Empty; } }

        /// <summary>
        /// 分片数量
        /// </summary>
        public int DistributeQuantity { get; set; }

        /// <summary>
        /// 叠层数量
        /// </summary>
        public int LaminatedQuantity { get; set; }

        /// <summary>
        /// 包装数量
        /// </summary>
        public int PackQuantity { get; set; }

        /// <summary>
        /// 入库数量
        /// </summary>
        public int InboundQuantity { get; set; }

        /// <summary>
        /// 入库达成率
        /// </summary>
        public decimal InboundRate { get; set; }

        /// <summary>
        /// BOM列表
        /// </summary>
        public List<VWorkOrderBom> Boms { get; set; } = new List<VWorkOrderBom>();
    }
}
